﻿Imports System.Data
Imports System.Data.SqlClient
Public Class KiemTraUsername_DAO
    Public Shared Function KiemTraDuLieu(ByVal NguoiDung As KiemTraUsername_DTO) As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Loadsername", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@ur", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@ps", NguoiDung.Password.ToString()))
        Dim data As DataTable = New DataTable()
        Dim data1 As SqlDataAdapter = New SqlDataAdapter()
        data1.SelectCommand = cm
        data1.Fill(data)
        cn.Close()
        Return data
    End Function
    Public Shared Function LayThongTinTaiKhoan() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("LoadThongtintaiKhoan", cn)
        cm.CommandType = CommandType.StoredProcedure

        Dim data As DataTable = New DataTable()
        Dim data1 As SqlDataAdapter = New SqlDataAdapter()
        data1.SelectCommand = cm
        data1.Fill(data)
        cn.Close()
        Return data
    End Function
    Public Shared Function ThemTaiKhoan(ByVal NguoiDung As KiemTraUsername_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Insertdangky", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@username", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@Password", NguoiDung.Password.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function XoaTaiKhoan(ByVal NguoiDung As String) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("xoataiKhoan", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@us", NguoiDung.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function DoiPass(ByVal NguoiDung As KiemTraUsername_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("doipassword", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@us", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@pas", NguoiDung.Password.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class
